"""
生成ava_val_excluded_timestamps_v2.2.csv
就是没有目标的帧
视频名，帧名
"""
import pickle
import csv

# 文件路径
pkl_file_path = r'D:\file\postgrad\experiment\bird_ava_dataset\avaMin_dense_proposals_val.pkl'
csv_file_path = r'D:\file\postgrad\experiment\bird_ava_dataset\annotations\ava_val_excluded_timestamps_v2.2.csv'

# 加载 pkl 文件
with open(pkl_file_path, 'rb') as file:
    data = pickle.load(file)

# 通过数据中的键获取视频ID，假设格式为 "video_id,frame_id"
video_ids = sorted(set(int(key.split(',')[0]) for key in data.keys()))

# 帧编号范围
frame_range = range(1, 13)  # 帧编号从 1 到 12

# 找出缺失的帧并记录
missing_frames = []

# 遍历所有视频ID
for video_id in video_ids:
    # 遍历每个视频的帧ID（1到12）
    for frame_id in frame_range:
        # 格式化键：video_id 和 frame_id
        key = f"{video_id},{str(frame_id).zfill(4)}"
        if key not in data:
            # 如果该帧的键不存在于数据中，记录缺失的帧
            missing_frames.append([video_id, frame_id])

    # 调试：输出当前视频ID处理结果
    if video_id % 100 == 0:  # 每100个视频输出一次
        print(f"Checked video {video_id}")

# 将缺失帧写入 CSV 文件
with open(csv_file_path, 'w', newline='') as csvfile:
    writer = csv.writer(csvfile)
    writer.writerows(missing_frames)

print(f"Missing frames have been written to {csv_file_path}")
